package com.huse.serverbase;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Tag;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .tags(new Tag("teacher", "讲师管理"),getTags())
                .select()
                //.paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();

    }

    private Tag[] getTags() {
        Tag[] tags = {
                new Tag("piggery", "猪宿舍操作api"),
                new Tag("pig", "猪信息api"),
                new Tag("video", "课程章节下的小节api"),
                new Tag("cmsAdmin", "后台内容管理api"),
                new Tag("cmsFront", "前台内容显示api"),
                new Tag("sms", "手机短信服务api"),
                new Tag("user", "用户服务api"),
                new Tag("weixinpay", "微信支付api")
        };
        return tags;
    }

    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("养猪达人")
                .description("本文档描述了与猪相关的操作接口定义")
                .version("1.0")
                .contact(new Contact("Xinxin", "http://huse.com", "891646968@qq.com"))
                .build();
    }

}
